//
//  CommentsBottomView.m
//  OnionHome
//
//  Created by fengjie on 2019/9/20.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "CommentsBottomView.h"
#import "ShareViewController.h"
#import "HomeCommentsController.h"

@interface CommentsBottomView ()
/**<#属性#>*/
@property (nonatomic,copy)tapCellButtonAction compleBlock;
@end

@implementation CommentsBottomView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}

-(void)creatUI{
    
    UIView * line = UIView.new;
    line.backgroundColor = UIColorFromRGB(0xE9EEE7);
    
    self.textFiledBgView = [self createTexFileView];
    
    
    [self addSubview:line];
    [self addSubview:self.mesageBtn];
    [self addSubview:self.collectionBtn];
    [self addSubview:self.dianzanBtn];
    [self addSubview:self.shareBtn];
    [self addSubview:self.textFiledBgView];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];

    [self.mesageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.collectionBtn.mas_left).offset(-16);
        make.top.mas_equalTo(line.mas_bottom).offset(16);
        make.bottom.mas_equalTo(-16);
        make.width.height.mas_equalTo(20);
    }];
    [self.collectionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.dianzanBtn.mas_left).offset(-16);
        make.top.mas_equalTo(line.mas_bottom).offset(16);
        make.bottom.mas_equalTo(-16);
        make.width.height.mas_equalTo(20);
    }];
    [self.dianzanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.shareBtn.mas_left).offset(-16);
        make.top.mas_equalTo(line.mas_bottom).offset(16);
        make.bottom.mas_equalTo(-16);
        make.width.height.mas_equalTo(20);
    }];
    [self.shareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(line.mas_bottom).offset(16);
        make.bottom.mas_equalTo(-16);
        make.width.height.mas_equalTo(20);
    }];
    
    [self.textFiledBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.bottom.mas_equalTo(0);
        make.right.mas_equalTo(self.mesageBtn.mas_left).offset(-16);
    }];
}
-(UIButton*)mesageBtn{
    if(!_mesageBtn){
        _mesageBtn= [UIButton buttonWithType:UIButtonTypeCustom];
        [_mesageBtn setBackgroundImage:IMAGE_NAMED(@"home_mesae") forState:UIControlStateNormal];
        _mesageBtn.badgeValue = @"999";
        _mesageBtn.badgeOriginX = 15;
        
        kWeakSelf(weakSelf);
        [_mesageBtn addActionHandler:^{
            PresentationObject * objcet = [PresentationObject sharedPresentationObject];
            objcet.subViewFrame = CGRectMake(0, 225, KScreenWidth, KScreenHeight - 225);
            [objcet showPresentingViewController:[weakSelf getCurrentViewController] PresentedViewController:[HomeCommentsController new]];
        }];

    }
    return _mesageBtn;
}
-(UIButton*)collectionBtn{
    if(!_collectionBtn){
        _collectionBtn= [UIButton buttonWithType:UIButtonTypeCustom];
        [_collectionBtn setBackgroundImage:IMAGE_NAMED(@"五角星") forState:UIControlStateNormal];
        [_collectionBtn setBackgroundImage:IMAGE_NAMED(@"五角星_selecet") forState:UIControlStateSelected];
        kWeakSelf(weakSelf);
        [_collectionBtn addActionHandler:^{
            weakSelf.collectionBtn.selected = !weakSelf.collectionBtn.selected;
        }];
    }
    return _collectionBtn;
}
-(UIButton*)dianzanBtn{
    if(!_dianzanBtn){
        _dianzanBtn= [UIButton buttonWithType:UIButtonTypeCustom];
        [_dianzanBtn setBackgroundImage:IMAGE_NAMED(@"ic_like_defut") forState:UIControlStateNormal];
        [_dianzanBtn setBackgroundImage:IMAGE_NAMED(@"ic_like_selected") forState:UIControlStateSelected];
        kWeakSelf(weakSelf);
        [_dianzanBtn addActionHandler:^{
            weakSelf.dianzanBtn.selected = !weakSelf.dianzanBtn.selected;
        }];

    }
    return _dianzanBtn;
}
-(UIButton*)shareBtn{
    if(!_shareBtn){
        _shareBtn= [UIButton buttonWithType:UIButtonTypeCustom];
        [_shareBtn setBackgroundImage:IMAGE_NAMED(@"image_1") forState:UIControlStateNormal];
        kWeakSelf(weakSelf);
        [_shareBtn addActionHandler:^{
            PresentationObject * object = [PresentationObject sharedPresentationObject];
            object.subViewFrame = CGRectZero;
            [object showPresentingViewController:[weakSelf getCurrentViewController] PresentedViewController:[ShareViewController new]];
        }];
    }
    return _shareBtn;
}
-(UITextField*)textField{
    if(!_textField){
        _textField=[UITextField new];
        _textField.placeholder = @"写评论…";
    }
    return _textField;
}
-(UIView * )createTexFileView{
    UIView * view = UIView.new;
    view.backgroundColor = UIColor.whiteColor;
    
    UIView * view1 = UIView.new;
    view1.backgroundColor = UIColorFromRGB(0xF5F7F5);
    ViewRadius(view1, 4);
    
    [view addSubview:view1];
    
    
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(30);
    }];
    
    UIImageView * leftImage = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"xiepinglun")];
    [view1 addSubview:leftImage];
    [view1 addSubview:self.textField];
    
    [leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(8);
        make.width.height.mas_equalTo(20);
    }];
    
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(leftImage.mas_right).offset(5);
        make.top.right.bottom.mas_equalTo(0);
    }];    
    
    return view;
}

/// 隐藏消息 和收藏按钮
-(void)hiddenLeftTwoBtn{
    self.mesageBtn.hidden = YES;
    self.collectionBtn.hidden = YES;
    
    
    
    [self.textFiledBgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(16);
//        make.top.bottom.mas_equalTo(0);
        make.right.mas_equalTo(self.dianzanBtn.mas_left).offset(-16);
    }];
}
-(void)settextFieldEnabled:(tapCellButtonAction)compleBlock{
    self.textField.enabled = NO;
    self.compleBlock = compleBlock;
    [self.textFiledBgView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapbottomViewAction)]];
}
-(void)tapbottomViewAction{
    BlockSafeRun(self.compleBlock);
}
@end


@interface CommentsTwoBottomView ()
/**<#属性#>*/
@property (nonatomic,copy)tapCellButtonAction compleBlock;

@end

@implementation CommentsTwoBottomView


-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}

-(void)creatUI{
    
    UIView * line = UIView.new;
    line.backgroundColor = UIColorFromRGB(0xE9EEE7);
    
    self.textFiledBgView = [self createTexFileView];
    
    
    [self addSubview:line];
    [self addSubview:self.dianzanBtn];
    [self addSubview:self.shareBtn];
    [self addSubview:self.textFiledBgView];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];

    [self.dianzanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.shareBtn.mas_left).offset(-16);
        make.top.mas_equalTo(line.mas_bottom).offset(16);
        make.bottom.mas_equalTo(-16);
        make.width.height.mas_equalTo(20);
    }];
    [self.shareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(line.mas_bottom).offset(16);
        make.bottom.mas_equalTo(-16);
        make.width.height.mas_equalTo(20);
    }];
    
    [self.textFiledBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.bottom.mas_equalTo(0);
        make.right.mas_equalTo(self.dianzanBtn.mas_left).offset(-16);
    }];
}
-(UIButton*)dianzanBtn{
    if(!_dianzanBtn){
        _dianzanBtn= [UIButton buttonWithType:UIButtonTypeCustom];
        [_dianzanBtn setBackgroundImage:IMAGE_NAMED(@"ic_like_defut") forState:UIControlStateNormal];
        [_dianzanBtn setBackgroundImage:IMAGE_NAMED(@"ic_like_selected") forState:UIControlStateSelected];
        kWeakSelf(weakSelf);
        [_dianzanBtn addActionHandler:^{
            weakSelf.dianzanBtn.selected = !weakSelf.dianzanBtn.selected;
        }];

    }
    return _dianzanBtn;
}
-(UIButton*)shareBtn{
    if(!_shareBtn){
        _shareBtn= [UIButton buttonWithType:UIButtonTypeCustom];
        [_shareBtn setBackgroundImage:IMAGE_NAMED(@"image_1") forState:UIControlStateNormal];
        kWeakSelf(weakSelf);
        [_shareBtn addActionHandler:^{
            PresentationObject * object = [PresentationObject sharedPresentationObject];
            object.subViewFrame = CGRectZero;
            [object showPresentingViewController:[weakSelf getCurrentViewController] PresentedViewController:[ShareViewController new]];
        }];
    }
    return _shareBtn;
}
-(UITextField*)textField{
    if(!_textField){
        _textField=[UITextField new];
        _textField.placeholder = @"写评论…";
    }
    return _textField;
}
-(UIView * )createTexFileView{
    UIView * view = UIView.new;
    view.backgroundColor = UIColor.whiteColor;
    
    UIView * view1 = UIView.new;
    view1.backgroundColor = UIColorFromRGB(0xF5F7F5);
    ViewRadius(view1, 4);
    
    [view addSubview:view1];
    
    
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(30);
    }];
    
    UIImageView * leftImage = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"xiepinglun")];
    [view1 addSubview:leftImage];
    [view1 addSubview:self.textField];
    
    [leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(8);
        make.width.height.mas_equalTo(20);
    }];
    
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(leftImage.mas_right).offset(5);
        make.top.right.bottom.mas_equalTo(0);
    }];
    
    return view;
}

-(void)settextFieldEnabled:(tapCellButtonAction)compleBlock{
    self.textField.enabled = NO;
    self.compleBlock = compleBlock;
    [self.textFiledBgView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapbottomViewAction)]];
}
-(void)tapbottomViewAction{
    BlockSafeRun(self.compleBlock);
}

@end
